package com.mftour.moudles.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mftour.moudles.entity.RoleUser;
import com.mftour.moudles.mapper.RoleUserMapper;
import com.mftour.moudles.service.RoleUserService;

@Service
public class RoleUserServiceImpl extends BaseServiceImpl<RoleUser, Integer> implements RoleUserService {
	@Autowired
	RoleUserMapper roleUserMapper;

	@Override
	public boolean updateRoleUsers(String userIds, Integer roleId) {
		boolean result = false;
		RoleUser record = new RoleUser();
		record.setRoleId(roleId);
		deleteSelective(record);
		RoleUser ru = new RoleUser();
		for (String userId : userIds.split(",")) {
			ru.setRoleId(roleId);
			ru.setUserId(Integer.parseInt(userId));
			insertSelective(ru);
		}
		result = true;
		return result;
	}

	@Override
	public boolean updateUserRoles(String roleIds, Integer userId) {
		boolean result = false;
		RoleUser record = new RoleUser();
		record.setUserId(userId);
		deleteSelective(record);
		RoleUser ru = new RoleUser();
		for (String roleId : roleIds.split(",")) {
			ru.setRoleId(Integer.parseInt(roleId));
			ru.setUserId(userId);
			insertSelective(ru);
		}
		result = true;
		return result;
	}
}